package com.transaction.demo.base.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import javax.validation.Valid;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.transaction.demo.base.vo.req.SaveUserRoleListReqVo;
import com.transaction.demo.base.vo.req.UserLoginReqVo;
import com.transaction.demo.base.vo.resp.UserLoginRespVo;
import com.transaction.demo.base.vo.resp.UserMenuResp;
import com.transaction.demo.base.vo.resp.UserRoleResp;
import com.transaction.demo.common.util.Result;
import com.transaction.demo.common.util.ResultPage;
import com.transaction.demo.base.vo.req.SysUserListReqVo;
import com.transaction.demo.base.vo.req.SysUserAddReqVo;
import com.transaction.demo.base.vo.req.SysUserUpdateReqVo;
import com.transaction.demo.base.vo.resp.SysUserRespVo;
import com.transaction.demo.base.service.SysUserService;

/**
 * 描述：用户信息表
 * 作者：马庆智
 * 日期：2023/03/28 17:07:15
 */
@Api(tags = "用户信息表")
@RestController
@RequestMapping("/sysUser")
public class SysUserController {

	@Autowired
	private SysUserService sysUserService;

	/**
	 * 用户登录
	 *
	 * @param record 请求参数
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:15
	 */
	@ApiOperation("用户登录")
	@PostMapping("/login")
	public Result<UserLoginRespVo> login(@RequestBody @Valid UserLoginReqVo record) {
		return Result.success(sysUserService.login(record));
	}

	/**
	 * 查询用户菜单
	 *
	 * @param userId 用户id
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/3/29 17:14
	 */
	@ApiOperation("查询用户菜单")
	@GetMapping("/queryUserMenuList")
	public Result<UserMenuResp> queryUserMenuList(@RequestHeader(value = "userId") Integer userId) {
		return Result.success(sysUserService.queryUserMenuList(userId));
	}

	/**
	 * 查询用户角色
	 *
	 * @param userId 用户id
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/3/30 9:18
	 */
	@ApiOperation("查询用户角色")
	@GetMapping("/queryUserRoleList")
	public Result<UserRoleResp> queryUserRoleList(@RequestParam(value = "userId") Integer userId) {
		return Result.success(sysUserService.queryUserRoleList(userId));
	}

	/**
	 * 分配用户角色
	 *
	 * @param record 请求参数
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/3/30 9:18
	 */
	@ApiOperation("分配用户角色")
	@PostMapping("/saveUserRoleList")
	public Result<Integer> saveUserRoleList(@RequestBody @Valid SaveUserRoleListReqVo record) {
		return Result.success(sysUserService.saveUserRoleList(record));
	}

	/**
	 * 查询用户信息表列表
	 *
	 * @param record 请求参数
	 * @return SysUserResp
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:15
	 */
	@ApiOperation("查询用户信息表列表")
	@PostMapping("/queryUserList")
	public Result<ResultPage<SysUserRespVo>> querySysUserList(@RequestBody @Valid SysUserListReqVo record) {
		return Result.success(sysUserService.querySysUserList(record));
	}

	/**
	 * 添加用户信息表
	 *
	 * @param record 请求参数
	 * @return Result<Integer>
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:15
	 */
	@ApiOperation("添加用户信息表")
	@PostMapping("/saveSysUser")
	public Result<Integer> saveSysUser(@RequestBody @Valid SysUserAddReqVo record) {
		return Result.success(sysUserService.saveSysUser(record));
	}

	/**
	 * 删除用户信息表
	 *
	 * @param ids 请求参数
	 * @return Result<Integer>
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:15
	 */
	@ApiOperation("删除用户信息表")
	@GetMapping("/deleteSysUser")
	public Result<Integer> deleteSysUser(String ids) {
		return Result.success(sysUserService.deleteSysUser(ids));
	}

	/**
	 * 更新用户信息表
	 *
	 * @param record 请求参数
	 * @return Result<Integer>
	 * @author 马庆智
	 * @date: 2023/03/28 17:07:15
	 */
	@ApiOperation("更新用户信息表")
	@PostMapping("/updateSysUser")
	public Result<Integer> updateSysUser(@RequestBody @Valid SysUserUpdateReqVo record) {
		return Result.success(sysUserService.updateSysUser(record));
	}

}